package com.dotflat.fin.controller;

import com.dotflat.fin.PO.FinPlanPO;
import com.dotflat.fin.domain.FinPlan;
import com.dotflat.fin.service.FinPlanService;
import com.dotflat.rest.controller.RestfulBaseController;
import com.matt.commons.dto.sso.StaffDTO;
import com.matt.commons.model.StatusResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.matt.foundation.constant.CommonConstant.TICKET;


/**
 * @author ：Ron
 * @date ：Created in 11/6/2020 5:07 PM
 */
@RestController
@RequestMapping("/fin/plan")
@Slf4j
@Api(tags = "财务 - 收费计划")
public class FinPlanController extends RestfulBaseController<FinPlan, FinPlanService, FinPlanPO> {

    @Autowired
    public void setBaseService(FinPlanService service){
        this.baseService = service;
    }

    @RequestMapping(value = "/notify_parents",method = RequestMethod.POST)
    @ApiOperation("通知家长")
    public  StatusResponse notifyParents(@RequestHeader(TICKET) String ticket, String planId) {
        StaffDTO staff = cache.getStaff(ticket);

        FinPlan plan = baseService.notifyParents(staff.getAreaId(), staff.getId(), planId);

        return StatusResponse.success(plan);
    }

    @RequestMapping(value = "/cancel",method = RequestMethod.POST)
    @ApiOperation("作废收费计划")
    public  StatusResponse cancelPlan(@RequestHeader(TICKET) String ticket, String planId) {
        StaffDTO staff = cache.getStaff(ticket);

        FinPlan plan = baseService.cancelPlan(staff.getAreaId(), staff.getId(), planId);

        return StatusResponse.success(plan);
    }

    @ApiOperation(value = "增加一条记录")
    @PostMapping()
    @Override
    public StatusResponse add(@RequestHeader(TICKET) String ticket, FinPlanPO param){
        if (param.getCancelled() == null){
            param.setCancelled(false);
        }

        return super.add(ticket, param);
    }


}
